package DomainLayer;
import java.util.ArrayList;
import java.util.Date;

public class Loan
{
    private int id;
    private ArrayList<Tool> tools;
    private Customer customer;
    private Assistant assistant;
    
    private int year;
    private int day;
    private int month;
    
    private int lastYear;
    private int lastDay;
    private int lastMonth;
    
    private InvoiceLoan invoiceLoan;

    /**
     * @param id a unique number of Loan.
     * @param tools a list of loeaned materials.
     * @param customer a customer who rent tools.
     * @param assitant an employee who lease out tools.
     * @param year, month, day - the date when lease out was made.
     */
    public Loan(int id, ArrayList<Tool> tools, Customer customer, Assistant assistant,int year, int month, int day )
    {
        this.id=id;
        this.tools=tools;
        this.customer=customer;
        this.assistant=assistant;
        this.year=year;
        this.month=month;
        this.day=day;
              
    }
    
    public int getID()
    {
        return id;
    }
    
    //@return list of items customer rents.
    public ArrayList<Tool> getLoanList()
    {
        return tools;
    }
    
    public Customer getCustomer()
    {
        return customer;
    }
    
    public Assistant getAssistant()
    {
        return assistant;
    }
    
    public int getYear()
    {return year;
    }
    public int getDay()
    {
        return day;
    }
    public int getMonth()
    {
        return month;
    }
    
    
    public void setLastYear(int lastYear)
    {
        this.lastYear=lastYear;
    }
    
    
    public void setLastMonth(int lastMonth)
    {
        this.lastMonth=lastMonth;
    }
    
    public void setLastDay(int lastDay)
    {
        this.lastDay=lastDay;
    }
    
    
    public int getLastYear()
    {
        return lastYear;
    }
    
    public int getLastMonth()
    {
        return lastMonth;
    }
    
    public int getLastDay()
    {
        return lastDay;
    }
     
    //@return price a totalPrice per day for all rented items.
    public double pricePerDay()
    {double price=0;
        for(Tool tool: getLoanList())
        {
            price+=tool.getPricePerDay();
        }
        return price;
    }
    
    public String createInvoice(int days)
    {
        invoiceLoan = new InvoiceLoan(toString(), totalDeposit(), pricePerDay(), days);
        return invoiceLoan.printInvoiceLoan();
    }
    
    //@return deposit a total amount of money for all the items to deposit.
    public double totalDeposit()
    {
        double deposit=0;
        for(Tool tool: getLoanList())
        {
            deposit+=tool.getDeposit();
        }
        return deposit;
    }
            
    //@return string an iformation about the leasing.
    public String toString()
    {
        String s= "Loan nr.: " + getID() +'\n'+ "Loan List: " + '\n' ;
        for(Tool tool: getLoanList())
        {
            s+=tool.toStrings() + "\nID: "+ tool.getID() + '\n';
        }
        s+="Deposit paid: " + totalDeposit()+'\n';
        s+="Price per day for all tools: " +pricePerDay()+'\n';
        s+="Customer Name: " + getCustomer().getName() +'\n';
        s+="Assistant's name: " +getAssistant().getName() + '\n';
        s+="Loan started at: " + getYear()+"/" + getMonth() + "/" + getDay() + '\n';
        if(getLastYear()==0)
        {
            s+="Loan not finished+\n";
        }
        else
        {
            s+="Loan finished at: " +getLastYear()+"/" + getLastMonth() + "/" + getLastDay() + '\n';
        }
        
        return s;
    
    
    }
        
}